package com.friend.chat.chat

import androidx.lifecycle.MutableLiveData
import com.friend.chat.net.BaseResult
import com.friend.chat.base.BasicViewModel
import com.friend.chat.websocket.ChatMessageBean

/**
 * @des
 * @author batie fancy
 * @date 2023/1/8
 */
class SingleChatViewModel: BasicViewModel()  {
    //未读消息
    val unReadListResponse by lazy { MutableLiveData<BaseResult<List<ChatMessageBean>>>() }

    fun getUnReadChatList(chatId:String,userId:String) {
        netWorkJob(
            successResult = {
                val data = mRepository.getUnReadChatList(chatId,userId)
                if (!data.isOk()) {
                    toast(data.message)
                } else {
                    unReadListResponse.value = data
                }
            },
            errorResult = {
                toast("错误")
            }
        )
    }


    val uploadPicResponse by lazy { MutableLiveData<BaseResult<String>>() }
    fun uploadImage(path:String) {
        netWorkJob(
            successResult = {
                val data = mRepository.uploadHeader(path)
                if (!data.isOk()) {
                    toast(data.message)
                } else {
                    uploadPicResponse.value = data
                }
            },
            errorResult = {
                toast("错误")
            }
        )
    }
}